function comment(id,uid)
{
	
		body = $('commentbody').value;
		privacy = $('privacy').value;


	  var commentObj = {"id": id, "userid" : uid, "body": body, "privacy": privacy}
	  var commentJSON = escape(Object.toJSON(commentObj));	
		
	  var sr = new Ajax.Request("/post/CommentAjax/id/"+id, 
	  {
	     method:'post',
	     parameters:'commentObj='+commentJSON,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			 	 //var structure = '<div id="shout_'+msg.id+'"><a href="/user/showProfile/id/'+msg.AuthorId+'">'+msg.AuthorName+'</a>: '+msg.body+'<br></div>';
			
				 if (msg.Privacy == '1') {
				 
			 	 var structure = '<div style="padding:10px;border:1px solid #ccc;background-color:#EFE0E0" id="'+msg.id+'">';
				 structure += '<span style="font-size:16px;color:#5f5f5f">';
				 structure += ''+msg.AuthorName+':<br>';
				 structure += ''+msg.Body+'<BR>';
				 structure += '</span>';
				 structure += '</div>';
				 structure += '<br>';
				 
				 } else {
				 
				 var structure = '<div style="padding:10px;border:1px solid #ccc" id="'+msg.id+'">';
				 structure += '<span style="font-size:16px;color:#5f5f5f">';
				 structure += ''+msg.AuthorName+':<br>';
				 structure += ''+msg.Body+'<BR>';
				 structure += '</span>';
				 structure += '</div>';
				 structure += '<br>';
				 
				 }
				 
	  			$('comments').insert({bottom:structure});

				  $('commentbody').value = '';
			
	
	         }
	      }.bind(this)
	    });
}



function connectFbUserFront() {

new Ajax.Request('/user/connectFbUser',
			  {
			    method:'post',

			    onSuccess: function(request)
			    {
			    window.location = "/";
				
			    }
			  });	

}

function connectFbUser() {

    
	new Ajax.Request('/user/connectFbUser',
		  {
		    method:'post',

		    onSuccess: function(request)
		    {
		    
		  

		    
			    window.location = "/";
			
		    }
		  });	

}


function update_user_box() { 

		var user_box = document.getElementById("user"); 
		var logoutlink = document.getElementById("logoutlink"); 
		
 		//var uid = FB.Facebook.apiClient.get_session().uid;
 		
 		var fbuser = FB.Connect.get_loggedInUser();
 		var uid = fbuser;

		//fbuidinput.value = uid;

		// add in some XFBML. note that we set useyou=false so it doesn't display "you" 
		user_box.innerHTML = "<span>" 
		+ "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account for workforoptions.<br>"
		+ '<span style="font-size:18px;color:#4C67A1">Click <fb:login-button class="FB_ElementReady fb_login_not_authorized" onlogin="connectFbUser()" length="short" background="white" size="medium">'
		+ '<a id="RES_ID_fb_login" class="fbconnect_login_button">'
		+ '<img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_white_large_short.gif?7:121638" alt="Connect"/>'
		+ '</a>'
		+ '</fb:login-button>'
		+ " to login</span></span>";
		
		
		logoutlink.innerHTML = '<a href=\"#\" onClick=\"FB.Connect.logout()\">[logout]</a>';
		
		user_box.style.display = '';
		// because this is XFBML, we need to tell Facebook to re-process the document 
		FB.XFBML.Host.parseDomTree();


} 

function logoutFbUser() {

	FB.Connect.logout();
	window.location = "/";

}

function FBConnectFront() {

 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
 //Debug app
 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");
 //FB.Connect.requireSession(false);

 //FB.Connect.showPermissionDialog("email"); 
 
 });
  

}


function FBConnect() { 
 

 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
  //Debug app
  //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");

 //FB.Connect.showPermissionDialog("email"); 
  FB.Connect.ifUserConnected(update_user_box);

 
 });
 
 
 
 
}

function FBConnectAppReg() {
 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
  //Debug app
 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");

 //FB.Connect.showPermissionDialog("email"); 
 FB.Connect.ifUserConnected(updateAppRegTable);

 
 });
 
 
 
}


function updateAppRegTable() { 

		var user_box = document.getElementById("user"); 
		var firstrow = document.getElementById("firstnamerow");
		var lastrow = document.getElementById("lastnamerow");
		var passwordrow = document.getElementById("passwordrow");
		var emailrow = document.getElementById("emailrow");
		var invitekeyrow = document.getElementById("fbinvitekeyrow");
 		//var uid = FB.Facebook.apiClient.get_session().uid;
 		
 		
 		FB.Bootstrap.requireFeatures(["Connect"], function() { 
		 //Prod
		 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
		  //Debug app
		 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");
		
		 //FB.Connect.showPermissionDialog("email"); 
		// FB.Connect.ifUserConnected(updateAppRegTable);
		 		var fbuser = FB.Connect.get_loggedInUser();

		 
		 });
 		
 		
 		var uid = fbuser;
		firstrow.style.display = 'none';
		lastrow.style.display = 'none';
		emailrow.style.display = 'none';
		passwordrow.style.display = 'none';
		invitekeyrow.style.display = 'none';
		$('fbflag').value = 'true';
		//invitekeyrow.style.display = 'none';
		//fbuidinput.value = uid;

		// add in some XFBML. note that we set useyou=false so it doesn't display "you" 
		user_box.innerHTML = "<span style='font-size:18px;color:#4C67A1'>" 
		+ "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account for workforoptions.<br>"
		+ '<span style="font-size:18px;color:#4C67A1">'
		+ "</span></span>";
		
		user_box.style.display = '';
		// because this is XFBML, we need to tell Facebook to re-process the document 
		FB.XFBML.Host.parseDomTree();


} 

function sendInvite(postid) {

		email = $('inviteemail').value;

new Ajax.Request('/user/inviteUser',
			  {
			    method:'post',
	   			parameters:'email='+email+'&postid='+postid,
			    onSuccess: function(request)
			    {
 		  var msg = request.responseText.evalJSON();
	         if(msg) {
	         
				$('inviteemail').value = 'Invited!';
	         
	         }
	         
	         
	         				
			    }
			  });	

}

